<?php
defined('BASEPATH') OR exit('No direct script access allowed');


class Courts extends CI_Controller
{

	public function __construct()
	{
		parent::__construct();
		$this->load->model('Court_Model');
		$this->load->helper('url_helper');
	}
	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 *        http://example.com/index.php/welcome
	 *    - or -
	 *        http://example.com/index.php/welcome/index
	 *    - or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see https://codeigniter.com/user_guide/general/urls.html
	 */
	public function index()
	{

	}
	public function courtlist($region_id=1){
		$courts=$this->Court_Model->get_courts_by_region($region_id);
		$data['title']='';
		switch($region_id){
			case 1:
				$data['title']='杭州市';
				break;
			case 2:
				$data['title']='宁波市';
				break;
			case 3:
				$data['title']='温州市';
				break;
			case 4:
				$data['title']='嘉兴市';
				break;
			case 5:
				$data['title']='湖州市';
				break;
			case 6:
				$data['title']='绍兴市';
				break;
			case 7:
				$data['title']='金华市';
				break;
			case 8:
				$data['title']='衢州市';
				break;
			case 9:
				$data['title']='舟山市';
				break;
			case 10:
				$data['title']='台州市';
				break;
			case 11:
				$data['title']='丽水市';
				break;
		}

		$court_rows_array=$this->make_court_list($courts);
		$data['court_rows_array']=$court_rows_array;
		$this->load->view('head_sec',$data);
		$this->load->view('weiMix/court_list',$data);
		$this->load->view('foot_sec',$data);
	}

	private function make_court_list($courts){
		$court_num=count($courts);
		$rows=$this->calc_rows($court_num);
		$court_rows_array=array();
		for($i=0;$i<$rows;$i++){
			$row_array=array();
			$jmax=0;
			if($i*3+3<$court_num){
				$jmax=$i*3+3;
			}else{
				$jmax=$court_num;
			}
			for($j=$i*3;$j<$jmax;$j++){
				array_push($row_array,$courts[$j]);
			}
			array_push($court_rows_array,$row_array);
		}
		return $court_rows_array;
	}

	private function calc_rows($court_num){
		$rows=intval($court_num/3);
		$col=intval($court_num%3);
		if($col !=0){
			$rows=$rows+1;
		}
		return$rows;
	}
}


